package ru.nosport.matrixaria.core;

import org.apache.commons.configuration.Configuration;
import junit.framework.TestCase;

import java.util.Properties;

/**
 *
 * User: vfabr
 * Date: 25.09.2006
 * Time: 13:38:26
 * 
 */
public class CoreVars {

	private static CoreVars getInstance;

	public final int initialRegSize;
	public final int dependenceDepth;
	public final float initialRegLoad;
	public final char charConfDelimiter;
//	public final String platform;
	public final String homePath;
	public final String defaultEncoding;
	public final String userModulesConf;
	public final String coreModulesConf;
	public final String remoteModulesConf;
	public final String userModuleConfPath;
	public final String remoteModuleConfPath;
	public final String coreModuleConfPath;
	public final String rmhName;
	public final String logPath;
	public final String coreLogName;
	public final String coreModuleLogName;
	public final String userModuleLogName;
	public final String remoteModuleLogName;
	public final String moduleInstanceName;

	public final String fileSysSep;


	synchronized public static CoreVars getInstance(){
		if(getInstance != null) {
			return getInstance;
		} else {
			throw new IllegalStateException("This class is not initialized. Instance is null.");
		}
	}

	synchronized public static void init(Configuration _xmlConf) {
		if(getInstance == null) {
			getInstance = new CoreVars (_xmlConf);
		}
	}

	synchronized public static void uninit(Object _obj) {
		if((_obj instanceof Init) || (_obj instanceof TestCase)) {
			if(getInstance != null) {
				getInstance = null;
			}
		}
	}

	private CoreVars (Configuration _xmlConf) {
		this.initialRegSize = _xmlConf.getInt("sysVars.initialRegSize");
		this.dependenceDepth = _xmlConf.getInt("sysVars.dependenceDepth");
		this.initialRegLoad = _xmlConf.getFloat("sysVars.initialRegLoad");
//		this.platform = _xmlConf.getString("sysVars.platform");
		this.homePath = _xmlConf.getString("sysVars.homePath");
		this.defaultEncoding = _xmlConf.getString("sysVars.defaultEncoding");
		this.userModulesConf = _xmlConf.getString("sysVars.userModulesConf");
		this.coreModulesConf = _xmlConf.getString("sysVars.coreModulesConf");
		this.remoteModulesConf = _xmlConf.getString("sysVars.remoteModulesConf");
		this.userModuleConfPath = _xmlConf.getString("sysVars.userModuleConfPath");
		this.remoteModuleConfPath = _xmlConf.getString("sysVars.remoteModuleConfPath");
		this.coreModuleConfPath = _xmlConf.getString("sysVars.coreModuleConfPath");
		this.rmhName = _xmlConf.getString("sysVars.rmhName");
		this.logPath = _xmlConf.getString("sysVars.logs.path");
		this.coreLogName = _xmlConf.getString("sysVars.logs.coreLogName");
		this.coreModuleLogName = _xmlConf.getString("sysVars.logs.coreModuleLogName");
		this.userModuleLogName = _xmlConf.getString("sysVars.logs.userModuleLogName");
		this.remoteModuleLogName = _xmlConf.getString("sysVars.logs.remoteModuleLogName");
		this.charConfDelimiter = '`';//_xmlConf.getString("sysVars.charConfDelimiter").toCharArray()[0];
		this.moduleInstanceName = _xmlConf.getString("sysVars.moduleInstanceName");

		Properties props = System.getProperties();
		this.fileSysSep = props.getProperty("file.separator");
	}
}
